<%@page import="com.extr.controller.domain.QuestionQueryResult"%>
<%@page import="com.extr.util.xml.Object2Xml"%>
<%@page import="com.extr.domain.question.QuestionContent"%>
<%@page import="com.extr.domain.question.Question"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.springframework.util.StringUtils"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<%-- <%@taglib uri="spring.tld" prefix="spring"%> --%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String baseUrl = "http://" + request.getServerName() + ":" + request.getServerPort() + "/";
Question question = null;
String questionId = "";
QuestionContent questionContent = null;
boolean a_ = false;
boolean b_ = false;
boolean c_ = false;
boolean d_ = false;
boolean e_ = false;
boolean f_ = false;
String a_str="",b_str="",c_str="",d_str="",e_str="",f_str="";
String a_img="",b_img="",c_img="",d_img="",e_img="",f_img="";
String content_img = "",content_file = "",file_name = "";
if(request.getAttribute("question") != null){
	question = (Question)request.getAttribute("question");
	questionId = question.getId()+"";
	questionContent = Object2Xml.toBean(question.getContent(), QuestionContent.class);
	content_img = questionContent.getTitleImg();
	content_file = questionContent.getTitleFile();
	file_name = questionContent.getFileName();
	file_name = (file_name==null || file_name.equals(""))?"预览附件":file_name;
	String answer = question.getAnswer();
	if (question.getQuestion_type_id() == 1 || question.getQuestion_type_id() == 2) {
		//单选题 or 多选题
		a_ = answer.indexOf("A") > -1 ? true : false;
		b_ = answer.indexOf("B") > -1 ? true : false;
		c_ = answer.indexOf("C") > -1 ? true : false;
		d_ = answer.indexOf("D") > -1 ? true : false;
		e_ = answer.indexOf("E") > -1 ? true : false;
		f_ = answer.indexOf("F") > -1 ? true : false;
		Iterator<String> it = questionContent.getChoiceList().keySet().iterator();
		while (it.hasNext()) {
			String key = it.next();
			String value = questionContent.getChoiceList().get(key);
			String imageUrl = null;
			System.out.println(key+":"+value);
			if (questionContent.getChoiceImgList() != null) {
				if (questionContent.getChoiceImgList().containsKey(key)) {
					//imageUrl = baseUrl+questionContent.getChoiceImgList().get(key);
					imageUrl = questionContent.getChoiceImgList().get(key);
					System.out.println(key +" imageUrl: " + imageUrl);
				}
			}
			if(key.equals("A")){
				a_str = value;
				a_img = imageUrl;
			} else if(key.equals("B")) {
				b_str = value;
				b_img = imageUrl;
			} else if(key.equals("C")) {
				c_str = value;
				c_img = imageUrl;
			} else if(key.equals("D")) {
				d_str = value;
				d_img = imageUrl;
			} else if(key.equals("E")) {
				e_str = value;
				e_img = imageUrl;
			} else if(key.equals("F")) {
				f_str = value;
				f_img = imageUrl;
			}
		}
	}
}
String refrence = "",exam_point = "";
if(request.getAttribute("questionQueryResultMap") != null) {
	HashMap<Integer, QuestionQueryResult> questionQueryResultMap = (HashMap<Integer, QuestionQueryResult>)request.getAttribute("questionQueryResultMap");
	QuestionQueryResult questionQueryResult = questionQueryResultMap.get(question.getId());
	if(questionQueryResult != null) {
		refrence = questionQueryResult.getReferenceName();
		exam_point = questionQueryResult.getExamingPoint();
	}
}
%>

<!DOCTYPE html>
<html>
  <head>
    <base href="<%=basePath%>">
    
   		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<title>试题管理</title>
		<meta name="keywords" content="">
		<link rel="shortcut icon" href="<%=basePath%>resources/images/favicon.ico" />
		<link href="resources/bootstrap/css/bootstrap-huan.css" rel="stylesheet">
		<link href="resources/font-awesome/css/font-awesome.min.css" rel="stylesheet">
		<link href="resources/css/style.css" rel="stylesheet">
		<link href="resources/css/question-add.css" rel="stylesheet">
		<link href="resources/chart/morris.css" rel="stylesheet">
		<link href="resources/css/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
		<link href="resources/css/jquery-ui-1.9.2.custom.min.css" rel="stylesheet" type="text/css" />
		<!-- jQuery -->
		<script type="text/javascript" src="resources/js/jquery/jquery-1.9.0.min.js"></script>
		<script type="text/javascript" src="resources/js/all.js"></script>
		<script type="text/javascript" src="resources/js/jquery/jquery-ui-1.9.2.custom.min.js"></script>
		<script type="text/javascript" src="resources/js/jquery/jquery.autocomplete.js"></script>
		<style type="text/css">
			.uploadify-button-text{
				text-decoration: underline;
			}
			
			span.add-img{
				text-decoration: underline;
				cursor:pointer;
			}
			
			span.add-img:hover{
				text-decoration: underline;
			}
			span.add-file{
				text-decoration: underline;
				cursor:pointer;
			}
			
			span.add-file:hover{
				text-decoration: underline;
			}
			
			.swfupload {
   				z-index: 10000 !important;
			}
			
			.add-content-img{
				display:block;
			}
			.add-content-file{
				display:block;
			}
			
			.diaplay-img{
				margin-right:5px;
			}
			.diaplay-img:hover{
				text-decoration: underline;
			}
			.diaplay-file{
				margin-right:5px;
			}
			.diaplay-file:hover{
				text-decoration: underline;
			}
			.add-opt-item input{
				width: 360px;
			}
		</style>
	</head>
	<body>
		<header>
			<div class="container">
				<div class="row">
					<div class="col-xs-5">
						<div class="logo">
							<h1><a href="#">网站管理系统</a></h1>
							<div class="hmeta">
								专注互联网在线考试解决方案
							</div>
						</div>
					</div>
					<div class="col-xs-7" id="login-info">
						<c:choose>
							<c:when test="${not empty sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.username}">
								<div id="login-info-user">
									
									<a href="user-detail/${sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.username}" id="system-info-account">${sessionScope.SPRING_SECURITY_CONTEXT.authentication.principal.username}</a>
									<span>|</span>
									<a href="j_spring_security_logout"><i class="fa fa-sign-out"></i> 退出</a>
								</div>
							</c:when>
							<c:otherwise>
								<a class="btn btn-primary" href="user-register">用户注册</a>
								<a class="btn btn-success" href="user-login-page">登录</a>
							</c:otherwise>
						</c:choose>
					</div>
				</div>
			</div>
		</header>
		<!-- Navigation bar starts -->

		<div class="navbar bs-docs-nav" role="banner">
			<div class="container">
				<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
					<ul class="nav navbar-nav">
						<li>
							<a href="home"><i class="fa fa-home"></i>网站首页</a>
						</li>
						<li class="active">
							<a href="admin/question-list"><i class="fa fa-edit"></i>试题管理</a>
						</li>

						<li>
							<a href="admin/exampaper-list"><i class="fa fa-file-text-o"></i>试卷管理</a>
						</li>
						<li>
							<a href="admin/homework-list"><i class="fa fa-home-work"></i>作业管理</a>
						</li>
						<li>
							<a href="admin/user-list"><i class="fa fa-user"></i>学生管理</a>
						</li>
						<li>
							<a href="admin/field-list-1"><i class="fa fa-cloud"></i>题库管理</a>
						</li>
						<li>
							<a href="admin/sys-backup"><i class="fa fa-cogs"></i>网站设置</a>
						</li>
					</ul>
				</nav>
			</div>
		</div>

		<!-- Navigation bar ends -->

		<!-- Slider starts -->

		<div>
		<div class="content" style="margin-bottom: 100px;">
			<!-- Slider (Flex Slider) -->

			<div class="container" style="min-height:500px;">

				<div class="row">
					<div class="col-xs-3">
						<ul class="nav default-sidenav">
							<li>
								<a href="admin/question-list"> <i class="fa fa-list-ul"></i> 试题管理 </a>

							</li>
							<li class="active">
								<a> <i class="fa fa-pencil-square-o"></i> 修改试题 </a>

							</li>
							<li>
								<a href="admin/question-import"> <i class="fa fa-cloud-upload"></i> 导入试题 </a>

							</li>

						</ul>

					</div>
					<div class="col-xs-9">
						<div class="page-header">
							<h1><i class="fa fa-pencil-square-o"></i> 修改试题 </h1>
						</div>
						<div class="page-content row">
							<form id="question-add-form" style="margin-top:40px;">
								<input type="hidden" id="question-id" value="<%=questionId %>">
								<div class="form-line question-type" id="question-type">
									<span class="form-label"><span class="warning-label">*</span>试题类型：</span>
									<select id="question-type-select" class="df-input-narrow">
										<option value="1">单选题</option>
										<option value="2">多选题</option>
										<option value="3">判断题</option>
										<option value="4">填空题</option>
										<option value="5">简答题</option>
										<option value="6">论述题</option>
										<option value="7">分析题</option>
									</select><span class="form-message"></span>
								</div>
								<div class="form-line question-knowledge">
									<span class="form-label"><span class="warning-label">*</span>专业列表：</span>
									<div>
										<div class="clearfix">
											<div id="aq-course1" style="padding:0px;float:left; width:48%;">
												<select id="field-select" class="df-input-narrow" size="4" style="width:100%;height:200px;">
													<c:forEach items="${fieldList }" var="item">
														<option value="${item.fieldId }">${item.fieldName }</option>
													</c:forEach>
												</select>
											</div>
											<div id="aq-course2" style="padding:0px; float:right;width:48%;">
												<!-- 
												<select id="point-from-select" class="df-input-narrow" size="4"  style="width:100%;">
												</select>
												-->
											  <div>
										  	  	<select id="point-from-select" class="df-input-narrow" size="4"  style="width:100%;height:200px;">
												</select>
										  	  </div>
										   </div>
										</div>
										<div class="search-citys">
											<input type="text" class="df-input-narrow" id="point_name" style="width: 298px;" type="text" value="请输入知识点名称/拼音/首字母搜索" onKeyUp="input_keyup();" onClick="check_point_get();" onBlur="input_blur()" onFocus="getFocus(this)" />	
											<div class="pop search-citys-pop click" style="background-color: #F1F6FC;display:none;z-index:99999999999" id="pointarea">
												<a href="javascript:void(0)" class="pop-close" onclick="pop_click()"></a>
												<div class="search-citys-tit click">请选择具体知识点(可直接输入知识点名称/首字母或拼音)</div>
												<div class="search-citys-tt click" style="background-color: #F1F6FC;z-index:99999999999">
													<a class="click click" onClick="tabCutover(this,'s-citys2')" href="javascript:void(0)">ABCDEFG<span></span></a>
													<a class="click" onClick="tabCutover(this,'s-citys3')" href="javascript:void(0)">HIJKL<span></span></a>
													<a class="click" onClick="tabCutover(this,'s-citys4')" href="javascript:void(0)">MNOPQRST<span></span></a>
													<a class="click" onClick="tabCutover(this,'s-citys5')" href="javascript:void(0)">UVWXYZ<span></span></a>
												</div>
												<div class="search-citys-list click" id="citylist" style="width: 500px;background-color: #F1F6FC;z-index:99999999999"></div>
											</div>
										  </div>
										<div style="text-align:center;margin:10px 0;">
											<button id="add-point-btn" class="btn btn-primary btn-xs">选择知识点</button>
											<button id="del-point-btn" class="btn btn-danger btn-xs">删除知识点</button>
											<button id="remove-all-point-btn" class="btn btn-warning btn-xs">清除列表</button>
										</div>
										<div  id="kn-selected" style="padding-left:0px;text-align:center;margin-bottom:20px;">
												<select id="point-to-select" class="df-input-narrow" size="4"  style="width:100%;">
													<c:forEach items="${pointList }" var="knowLedgePoint">
														<option value="${knowLedgePoint.pointId }">${knowLedgePoint.pointName }</option>
													</c:forEach>
												</select>
												<p style="font-size:12px;color:#AAA;">您可以从上面选择4个知识点</p>
										</div>
									</div>
									<span class="form-message"></span>
								</div>
								
								<div class="form-line question-content">
									<span class="form-label"><span class="warning-label">*</span>试题内容：</span>
									<textarea class="add-question-ta">${question.questionContent.title }</textarea>		
									<% if(content_img != null && !content_img.equals("")){ %>
										<a href="..\<%=content_img %>" class="diaplay-img display-content-img" target="_blank" data-url="<%=content_img %>">预览图片</a>
									<%} %>	
									<% if(content_file != null && !content_file.equals("")){ %>
										<a href="..\<%=content_file %>" class="diaplay-file display-content-file" target="_blank" data-url="<%=content_file %>"><%=file_name %></a>
									<%} %>							
									<span class="add-img add-content-img" style="width:100px;">添加图片</span>
									<span class="add-file add-content-file" style="width:100px;">添加附件</span>
									<span class="form-message"></span>
								</div>
								<div class="form-line form-question-opt" style="display: block;">
									<span class="form-label"><span class="warning-label">*</span>选项：</span>
									<div class="add-opt-items">
										<span class="add-opt-item"><label class="que-opt-no">A</label>
											<input type="text" class="df-input-narrow form-question-opt-item" value="<%=a_str %>">
											<%if(a_img != null && !"".equals(a_img)){ %>
												<a href="..\<%=a_img %>" class="diaplay-img display-opt-img" target="_blank" data-url="<%=a_img %>">预览图片</a>
											<%} %>
											<span class="add-img add-opt-img">添加图片</span>
										</span>
										<span class="add-opt-item"><label class="que-opt-no">B</label>
											<input type="text" class="df-input-narrow form-question-opt-item" value="<%=b_str %>">
											<%if(b_img != null && !"".equals(b_img)){ %>
												<a href="..\<%=b_img %>" class="diaplay-img display-opt-img" target="_blank" data-url="<%=b_img %>">预览图片</a>
											<%} %>
											<span class="add-img add-opt-img">添加图片</span>
										</span>
										<span class="add-opt-item"><label class="que-opt-no">C</label>
											<input type="text" class="df-input-narrow form-question-opt-item" value="<%=c_str %>">
											<%if(c_img != null && !"".equals(c_img)){ %>
												<a href="..\<%=c_img %>" class="diaplay-img display-opt-img" target="_blank" data-url="<%=c_img %>">预览图片</a>
											<%} %>
											<span class="add-img add-opt-img">添加图片</span> <span><i class="small-icon ques-remove-opt fa fa-minus-square" title="删除此选项"></i></span>
										</span>
										<span class="add-opt-item"><label class="que-opt-no">D</label>
											<input type="text" class="df-input-narrow form-question-opt-item" value="<%=d_str %>">
											<%if(d_img != null && !"".equals(d_img)){ %>
												<a href="..\<%=d_img %>" class="diaplay-img display-opt-img" target="_blank" data-url="<%=d_img %>">预览图片</a>
											<%} %>
											<span class="add-img add-opt-img">添加图片</span> <span><i class="small-icon ques-remove-opt fa fa-minus-square" title="删除此选项"></i></span>
										</span>
										<%if(!StringUtils.isEmpty(e_str)) {%>
											<span class="add-opt-item"><label class="que-opt-no">E</label>
												<input type="text" class="df-input-narrow form-question-opt-item" value="<%=e_str %>">
												<%if(e_img != null && !"".equals(e_img)){ %>
													<a href="..\<%=e_img %>" class="diaplay-img display-opt-img" target="_blank" data-url="<%=e_img %>">预览图片</a>
												<%} %>
												<span class="add-img add-opt-img">添加图片</span> <span><i class="small-icon ques-remove-opt fa fa-minus-square" title="删除此选项"></i></span>
											</span>
										<%} %>
										<%if(!StringUtils.isEmpty(f_str)) {%>
											<span class="add-opt-item"><label class="que-opt-no">F</label>
												<input type="text" class="df-input-narrow form-question-opt-item" value="<%=f_str %>">
												<%if(f_img != null && !"".equals(f_img)){ %>
													<a href="..\<%=f_img %>" class="diaplay-img display-opt-img" target="_blank" data-url="<%=f_img %>">预览图片</a>
												<%} %>
												<span class="add-img add-opt-img">添加图片</span> <span><i class="small-icon ques-remove-opt fa fa-minus-square" title="删除此选项"></i></span>
											</span>
										<%} %>
									</div>
									<span id="ques-add-opt"><i class="small-icon fa fa-plus-square" title="添加选项"></i></span>
									<br>
									<span class="form-message"></span>
								</div>
								<div class="form-line form-question-answer1 correct-answer" style="display: block;">
									<span class="form-label"><span class="warning-label">*</span>正确答案：</span>
									<select class="df-input-narrow">
										<option value="A" ${question.answer eq 'A' ? 'selected' : '' }>A</option>
										<option value="B" ${question.answer eq 'B' ? 'selected' : '' }>B</option>
										<option value="C" ${question.answer eq 'C' ? 'selected' : '' }>C</option>
										<option value="D" ${question.answer eq 'D' ? 'selected' : '' }>D</option>
										<option value="D" ${question.answer eq 'E' ? 'selected' : '' }>E</option>
										<option value="D" ${question.answer eq 'F' ? 'selected' : '' }>F</option>
									</select><span class="form-message"></span>
								</div>
								<div class="form-line form-question-answer-muti correct-answer" style="display: none;">
									<span class="form-label"><span class="warning-label">*</span>正确答案：</span>

									<span class="muti-opt-item">
										<input type="checkbox" value="A" <%=a_?"checked":"" %> >
										<label class="que-opt-no">A</label>
										<br>
									</span>
									<span class="muti-opt-item">
										<input type="checkbox" value="B" <%=b_?"checked":"" %>>
										<label class="que-opt-no">B</label>
										<br>
									</span>
									<span class="muti-opt-item">
										<input type="checkbox" value="C" <%=c_?"checked":"" %>>
										<label class="que-opt-no">C</label>
										<br>
									</span>
									<span class="muti-opt-item">
										<input type="checkbox" value="D" <%=d_?"checked":"" %>>
										<label class="que-opt-no">D</label>
										<br>
									</span>
									<span class="form-message"></span>
								</div>
								<div class="form-line form-question-answer-boolean correct-answer" style="display: none;">
									<span class="form-label"><span class="warning-label">*</span>正确答案：</span>
									<select class="df-input-narrow">
										<option value="T" ${question.answer eq 'T' ? 'selected' : '' }>正确</option>
										<option value="F" ${question.answer eq 'F' ? 'selected' : '' }>错误</option>
									</select><span class="form-message"></span>
								</div>
								<div class="form-line correct-answer form-question-answer-text" style="display: none;">
									<span class="form-label form-question-answer-more"><span class="warning-label">*</span>参考答案：</span>
									<textarea class="add-question-ta"> ${question.answer } </textarea>									<span class="form-message"></span>
									<br>

								</div>
								<div class="form-line form-question-reference" style="display: block;">
									<span class="form-label"><span class="warning-label"></span>来源：</span>
										<input type="text" value="<%=refrence %>" class="df-input-narrow"><span class="form-message"></span>
									<br>
								</div>
								<div class="form-line form-question-examingpoint" style="display: block;">
									<span class="form-label"><span class="warning-label"></span>考点：</span>
										<input type="text" value="<%=exam_point %>" class="df-input-narrow"><span class="form-message"></span>
									<br>
								</div>
								<div class="form-line form-question-keyword" style="display: block;">
									<span class="form-label"><span class="warning-label"></span>关键字：</span>
										<input type="text" value="${question.keyword }" class="df-input-narrow"><span class="form-message"></span>
									<br>
								</div>
								<div class="form-line form-question-analysis" style="display: block;">
									<span class="form-label"><span class="warning-label"></span>题目解析：</span>
									<textarea class="add-question-ta">${question.analysis }</textarea><span class="form-message"></span>
									<br>

								</div>

								<div class="form-line">
									<input id="btn-save" value="保存" type="submit" class="df-submit">
								</div>
							</form>

						</div>
						<div class="modal fade">
						  <div class="modal-dialog">
						    <div class="modal-content">
						      <div class="modal-header">
						        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						        <h4 class="modal-title">图片上传工具</h4>
						      </div>
						      <div class="modal-body">
						        <div id="add-question-img-dialog" title="图片上传工具">
									 <form>
										<div class="form-line img-destination">
											<span class="form-label">添加至：</span>
											<label></label>
											<input type="hidden" value=""/>
										</div>
										<div class="form-line add-update-quetstionfile">
											<span class="form-label">上传图片：</span>
											<div id="div-file-list">
											</div>
											<div class="form-line" id="uploadify"></div>
											<span class="form-message">请上传png、jpg图片文件，且不能大于3M。为了使得图片显示正常，请上传的图片长宽比例为2:1</span>
										</div>
									</form> 
								</div>
						      </div>
						      
						    </div><!-- /.modal-content -->
						  </div><!-- /.modal-dialog -->
						</div>
						
						<div class="modal fade-file">
						  <div class="modal-dialog">
						    <div class="modal-content">
						      <div class="modal-header">
						        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
						        <h4 class="modal-title">附件上传工具</h4>
						      </div>
						      <div class="modal-body">
						        <div id="add-question-file-dialog" title="附件上传工具">
									 <form>
										<div class="form-line file-destination">
											<span class="form-label">添加至：</span>
											<label></label>
											<input type="hidden" value=""/>
										</div>
										<div class="form-line add-update-quetstionfile">
											<span class="form-label">上传文件：</span>
											<div id="div-file-list">
											</div>
											<div class="form-line" id="uploadify-file"></div>
											<span class="form-message">请将文件限制在10M以内，视频文件建议转换为flv格式后用户体验更好。</span>
										</div>
									</form> 
								</div>
						      </div>
						      
						    </div><!-- /.modal-content -->
						  </div><!-- /.modal-dialog -->
						</div>
					</div>
				</div>
			</div>
			
		</div>

		<footer>
			<div class="container">
				<div class="row">
					<div class="col-md-12">
						<div class="copy">
							<p>
								QingYaexam Copyright © <a href="http://www.qingyaexam.net/" target="_blank">qingyaexam</a> - <a href="." target="_blank">主页</a> | <a href="http://www.qingyaexam.net/" target="_blank">关于我们</a> | <a href="http://www.qingyaexam.net/" target="_blank">FAQ</a> | <a href="http://www.qingyaexam.net/" target="_blank">联系我们</a>
							</p>
						</div>
					</div>
				</div>

			</div>

		</footer>

		<!-- Slider Ends -->

		<!-- Javascript files -->
		<script type="text/javascript" src="resources/js/uploadify/jquery.uploadify3.1Fixed.js"></script>
		<script type="text/javascript" src="resources/js/question-upload-file.js"></script>
		<script type="text/javascript" src="resources/js/question-upload-img.js"></script>
		<script type="text/javascript" src="resources/js/field-2-point.js"></script>
		<script type="text/javascript" src="resources/js/question-edit.js"></script>
		<!-- Bootstrap JS -->
		<script type="text/javascript" src="resources/bootstrap/js/bootstrap.min.js"></script>
		<script type="text/javascript">
			//设置题目类型并触发选择
			function initQuestionTypeSelect(){
				$("#question-type-select option").each(function(i,n){
					if($(n).val() == "${question.question_type_id}") {
						$(n).attr("selected", true);
						$("#question-type select").trigger("change");
					}
				});
			}
			
			$().ready(function(){
				initQuestionTypeSelect();
			});
		</script>
	</body>
</html>